using System;
using System.Collections;
using BitMango;
using BMCommon;
using GTA;
using Holoville.HOTween;
using Holoville.HOTween.Plugins;
using SevenPieceGame;
using TMPro;
using UnityEngine;

public class LevelUpRewardPopupHandler : MonoBehaviour, IPopupWnd, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterPopup(object param)
	{
		this.isGetReward = false;
		this.giftBoxLocalPosition = (Vector3)param;
		this.giftBox.transform.localPosition = this.giftBoxLocalPosition;
		this.giftBox.transform.localScale = new Vector3(0.4f, 0.4f, 1f);
		this.giftBox.gameObject.SetActive(true);
		this.giftBoxOpen.gameObject.SetActive(false);
		this.btnRoot.transform.localScale = Vector3.zero;
		this.btnRoot.gameObject.SetActive(true);
		this.shine.transform.localScale = Vector3.zero;
		this.coin.transform.localScale = Vector3.zero;
		this.title.transform.localScale = Vector3.zero;
		this.btnVideoAdsGetBtn.transform.localScale = Vector3.zero;
		this.messageRoot.transform.localScale = Vector3.zero;
		this.videoBooster.gameObject.SetActive(false);
		this.bg.color = new Color(0f, 0f, 0f, 0f);
		this.coloredPaper.SetActive(false);
		this.SetVideoAds();
		int _count = PlayerPrefsManager.GetInt(PlayerPrefsManager.SAVE_STAGE_PIECE_COUNT, 0);
		this.rewardCount = _count;//UserLevel.GetRewardCoinCount();
		this.message.text = string.Format("Level up!\n<color=#CE9F47FF>You got the</color> <color=#FFE576FF>{0}</color> coins", this.rewardCount.ToString());
		base.StartCoroutine(this.coClearPopupAnimation());
	}

	public void OnLeavePopup()
	{
	}

	private void SetVideoAds()
	{
		this.btnVideoAds.SetActive(true);
		/*if (RewardAd.IsAdInterstitialReward("LevelUpReward"))
		{
			this.btnVideoAds.SetActive(true);
			this.btnVideoAdsDisable.SetActive(false);
		}
		else
		{
			this.btnVideoAds.SetActive(false);
			this.btnVideoAdsDisable.SetActive(true);
		}*/
	}

	private void OnClickVideoAds()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		ADSHelper.ShowRewardedVideoAd((status) =>
		{
			if (status)
			{
				this.isGetReward = true;
				this.btnRoot.gameObject.SetActive(false);
				Wallet.Gain("blockcoin", this.rewardCount * 2, null);
				Wallet.Save();
				this.VideoBoosterAnimation();
				EconomyLog.SendEconomyLog(LOG_FROM.LEVEL_UP_REWARD, LOG_TYPE.SUPPLY, "blockcoin", this.rewardCount);
				this.coinInfo.CoinAnimation(this.cam.transform.InverseTransformPoint(this.coinAnimationPosition.transform.position), 5, 0.075f, this.rewardCount * this.videoMul, delegate
				{
					Scene.ClosePopup("LevelUpRewardPopup", null);
				});
			}
		}, ERVType.SevenPiece.ToString());
		
	}

	private void OnClickOk()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		UserLayerManager.Instance.CheckInstallToLowUser();
		if (UserLayerManager.Instance.GetCurrentUserLayer() == UserLayerManager.UserLayerType.LowUser
		    || UserLayerManager.Instance.GetCurrentUserLayer() == UserLayerManager.UserLayerType.Organic)
		{
			ADSHelper.ShowInterstitialAd("", AdsDataMgr.EInterstitiaFireScene.Seven);
		}
		
		this.isGetReward = true;
		this.btnRoot.gameObject.SetActive(false);
		Wallet.Gain("blockcoin", this.rewardCount, null);
		Wallet.Save();
		EconomyLog.SendEconomyLog(LOG_FROM.LEVEL_UP_REWARD, LOG_TYPE.SUPPLY, "blockcoin", this.rewardCount);
		this.coinInfo.CoinAnimation(this.cam.transform.InverseTransformPoint(this.coinAnimationPosition.transform.position), 5, 0.075f, this.rewardCount, delegate
		{
			Scene.ClosePopup("LevelUpRewardPopup", null);
		});
	}

	private void VideoBoosterAnimation()
	{
		this.num = this.rewardCount;
		this.videoBooster.gameObject.SetActive(true);
		this.videoBooster.gameObject.transform.localPosition = new Vector3(1.55f, 2f, -2f);
		Color color = this.videoBooster.color;
		this.videoBooster.color = new Color(color.r, color.g, color.b, 1f);
		Sequence sequence = new Sequence(new SequenceParms().OnComplete(delegate()
		{
			this.videoBooster.gameObject.SetActive(false);
		}));
		sequence.Insert(0f, HOTween.To(this.videoBooster.gameObject.transform, 1f, new TweenParms().Prop("localPosition", this.videoBooster.gameObject.transform.localPosition + Vector3.up * 1f)));
		sequence.Insert(0f, HOTween.To(this.videoBooster, 1f, new TweenParms().Prop("color", new Color(color.r, color.g, color.b, 0f))));
		TweenParms p_parms = new TweenParms().Prop("num", this.rewardCount * this.videoMul).Ease(EaseType.EaseOutSine).OnUpdate(delegate()
		{
			this.UpdateText();
		}).OnComplete(delegate()
		{
			this.num = this.rewardCount * this.videoMul;
		});
		sequence.Insert(0f, HOTween.To(this, 1f, p_parms));
		sequence.Play();
	}

	private void UpdateText()
	{
		//this.message.text = string.Format("Level up!\n<color=#CE9F47FF>You got the</color> <color=#FFE576FF>{0}</color> coins", this.num.ToString());
		int _count = PlayerPrefsManager.GetInt(PlayerPrefsManager.SAVE_STAGE_PIECE_COUNT, 0);
		this.message.text = string.Format("Level up!\n<color=#CE9F47FF>You got the</color> <color=#FFE576FF>{0}</color> coins", _count);
	}

	private IEnumerator coClearPopupAnimation()
	{
		this.giftBox.gameObject.SetActive(true);
		Vector3[] path = new Vector3[3];
		Vector3 position = this.giftBox.transform.localPosition;
		Vector3 position2 = new Vector3(0f, 1.86f, position.z);
		path[0] = position;
		path[1] = new Vector3(position.x + 1f, position.y - 1f, position.z);
		path[2] = position2;
		Sequence seq = new Sequence(new SequenceParms().OnComplete(delegate()
		{
		}));
		seq.Insert(0f, HOTween.To(this.giftBox.gameObject.transform, 1f, new TweenParms().Prop("localScale", Vector3.one).Ease(EaseType.EaseInCubic)));
		seq.Insert(0f, HOTween.To(this.giftBox.gameObject.transform, 1f, new TweenParms().Prop("localPosition", new PlugVector3Path(path, PathType.Curved)).Ease(EaseType.EaseInOutSine)));
		seq.Insert(0f, HOTween.To(this.bg, 1f, new TweenParms().Prop("color", new Color(0f, 0f, 0f, 0.8f))));
		seq.Play();
		yield return new WaitForSeconds(1.2f);
		seq = new Sequence();
		seq.Insert(0f, this.giftBox.gameObject.Bounce(0.2f, 2, 0.2f, null));
		seq.Insert(0f, this.giftBox.gameObject.ShakeRot(0.4f, 7f));
		this.giftBox.transform.localRotation = Quaternion.identity;
		seq.Play();
		yield return new WaitForSeconds(0.405f);
		this.giftBox.transform.localPosition = this.giftBoxLocalPosition;
		BMSoundHelper.Play("se_questreward", false, 1f);
		this.coloredPaper.SetActive(true);
		this.giftBox.gameObject.SetActive(false);
		this.giftBoxOpen.gameObject.SetActive(true);
		this.shine.gameObject.Popup(0.5f);
		this.coin.gameObject.Popup(0.5f);
		GameObject obj = UnityEngine.Object.Instantiate<GameObject>(this.particle);
		obj.transform.parent = this.particleRoot.gameObject.transform;
		obj.transform.localPosition = Vector3.zero;
		//obj.GetComponent<ParticleEmitter>().emit = true;
		yield return new WaitForSeconds(0.2f);
		this.title.gameObject.Popup(0.5f);
		yield return new WaitForSeconds(0.2f);
		this.messageRoot.gameObject.Popup(0.5f);
		yield return new WaitForSeconds(0.4f);
		this.btnRoot.gameObject.Popup(0.5f);
		BMSoundHelper.Play("se_gethint", false, 1f);
		yield return new WaitForSeconds(2f);
		this.btnVideoAdsGetBtn.gameObject.Popup(0.5f);
		yield break;
	}

	private void OnEscape()
	{
		if (!this.isGetReward)
		{
			this.OnClickOk();
		}
	}

	[SerializeField]
	private tk2dCamera cam;

	[SerializeField]
	private GameObject curtain;

	public GameObject btnRoot;

	public GameObject coloredPaper;

	public GameObject particle;

	public GameObject particleRoot;

	public GameObject coin;

	public GameObject coinAnimationPosition;

	public TextMeshPro message;

	public TextMeshPro videoBooster;

	public GameObject btnVideoAds;

	public GameObject btnVideoAdsDisable;

	public GameObject btnVideoAdsGetBtn;

	public tk2dSprite giftBox;

	public tk2dSprite giftBoxOpen;

	public tk2dSprite bg;

	public GameObject shine;

	public GameObject title;

	public GameObject messageRoot;

	public TopOverlayHandler coinInfo;

	private int rewardCount;

	private int videoMul = 2;

	private Vector3 giftBoxLocalPosition;

	private bool isGetReward;

	[HideInInspector]
	public int num;
}
